
import json
#转为json数据
# data1 = json.dumps({"张三": 1, "李四": 2, "王五": 3})
# print(data1) # {"\u5f20\u4e09": 1, "\u674e\u56db": 2, "\u738b\u4e94": 3}
#中文需要添加ensure_ascii=False
data1 = json.dumps({"张三": 1, "李四": 2, "王五": 3},ensure_ascii=False)
print(data1) # {"张三": 1, "李四": 2, "王五": 3}
print(type(data1)) # <class 'str'>
data2 = json.dumps([1,1,2,3,4,5],ensure_ascii=False)
print(data2) # [1, 1, 2, 3, 4, 5]
print(type(data2)) # <class 'str'>

#解析json数据
data3 = json.loads(data1)
print(data3) # {'张三': 1, '李四': 2, '王五': 3}
print(type(data3))# <class 'dict'>
data4 = json.loads(data2)
print(data4)# [1, 1, 2, 3, 4, 5]
print(type(data4))# <class 'list'>


print(len("A".encode("utf-8")))   # 输出：1
print(len("张".encode("utf-8")))  # 输出：3
print(len("😊".encode("utf-8")))  # 输出：4